import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
//import Axios from "./util/maxios.js";
import Axios from "axios";
import Api from "./api";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);
Vue.prototype.$api = Api;
Vue.prototype.$axios = Axios;
Vue.config.productionTip = false;

if (process.env.NODE_ENV === 'development') { // 说明当前为开发环境
  // 开发环境相关特殊方法
  Axios.defaults.baseURL = process.env.VUE_APP_BASE_URL;
} else if (process.env.NODE_ENV === 'production') {
  // 生产环境相关特殊方法
  Axios.defaults.baseURL = process.env.VUE_APP_BASE_URL;
}

Axios.interceptors.request.use(request => {
  console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
  this.$store.dispatch('loadingStart'); // 显示loading组件
  /* if (store.getters.token) {
      request.headers['X-Token'] = getToken() // 让每个请求携带token--['X-Token']为自定义key
  } */
  return request;
}, error => {
  console.log("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
  this.$store.dispatch('loadingEnd');
  return Promise.reject(error);
});

//4.2 添加响应拦截器
Axios.interceptors.response.use(response => {
  console.log("ccccccccccccccccccccccccccccccccccc");
  this.$store.dispatch('loadingEnd');
  return response;
}, error => {
  console.log("ddddddddddddddddddddddddddddddddddd");
  this.$store.dispatch('loadingEnd');
  return Promise.reject(error);
});


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
